Page({

  myLocation: function () {
    var that = this;
    wx.getLocation({
      success: function (res) {
        //console.log(res.latitude);
        that.setData({

          latitude: res.latitude,
          longitude: res.longitude
        })
        // la = res.latitude,
        //   long = res.longitude
      }
    })

  },

  // moveToLocation: function () {
  //   this.mapCtx.moveToLocation();

  //   // wx.chooseLocation({
  //   //   success: function (res) {
  //   //     that.setData({
  //   //       name: res.name,
  //   //       address: res.address,
  //   //       lat: res.latitude,
  //   //       lon: res.longitude
  //   //     })
  //   //   }
  //   // })
  //   //fail: function(res) {},
  //   //complete: function(res) {},
  // },

  cli: function (e) {
    let data = e.currentTarget.dataset.date;
    let map = this.data.incident;
    let keys = Object.keys(map);

    console.log(keys);
    console.log(e.currentTarget.dataset.date);
    for (var i = 0; i < keys.length; i++) {
      if (data == keys[i]) {
        wx.showModal({
          title: '日程',
          content: keys[i] + " " + map[keys[i]],
          showCancel: false
        })
      }
    }
    // if(data=="2019101"){
    //   wx.showModal({
    //     title: '日程',
    //     content: '国庆节',
    //     showCancel:false
    //   })
    // }


  },
  /*
   * 页面的初始数据
   */
  data: {
    key: '',
    incident: {
      "2019101": "国庆节",
      "20191231": "公司聚会",
      "202011": "元旦"
    },
    data: '',
    array: [1, 2, 3, 4, 5, 6, 7, 8, 9],
    //year: 2000,
    month: 0,
    date: ['日', '一', '二', '三', '四', '五', '六'],
    dateArr: [],
    isToday: 0,
    isTodayWeek: false,
    todayIndex: 0,
    latitude: "",
    longitude: "",
    markers: "",
    word: "金陵科技学院食堂"

  },

  keyInput: function (e) {
    this.setData({
      key: e.detail.value
    });
  },
  dataInput: function (e) {
    this.setData({
      data: e.detail.value
    })
  },
  setStorage: function (e) {
    let key = this.data.key;
    if (key.length == 0) {
      wx.showToast({
        title: '姓名不能为空',
        icon: 'none'
      })
    } else {
      wx.setStorage({
        key: key,
        data: this.data.data,
      })
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let now = new Date();
    let year = now.getFullYear();
    //let year = 2003;
    let month = now.getMonth() + 1;
    this.dateInit();
    this.setData({
      year: year,
      month: month,
      isToday: '' + year + month + now.getDate()
    })
    //this.mapCtx.moveToLocation();
    var long;
    var la;
    var that = this;
    long = 118.89987;
    la = 31.90523;
    wx.getLocation({

      type: 'gcj02',
      success(res) {
        that.setData({

          latitude: la,
          longitude: long,
          markers: [{
            id: 1,
            height: 50,
            width: 50,
            latitude: la,
            longitude: long,

            iconPath: '/images/icon/location.png',
            callout: {
              content: that.data.word,
              bgColor: "#fff",
              padding: "5px",
              borderRadius: "2px",
              borderWidth: "1px",
              borderColor: "#07c160",
            }
          },
          {
            id: 2,
            height: 50,
            width: 50,
            latitude: res.latitude,
            longitude: res.longitude + 0.01,
            iconPath: '/images/icons/location.png',
            callout: {
              content: "实际地址",
              bgColor: "#fff",
              padding: "5px",
              borderRadius: "2px",
              borderWidth: "1px",
              borderColor: "#07c160",

            }
          }

          ]

        })
      }
    })
  },
  dateInit: function (setYear, setMonth) {
    //全部时间的月份都是按0~11基准，显示月份才+1
    let dateArr = []; //需要遍历的日历数组数据
    let arrLen = 0; //dateArr的数组长度
    let now = setYear ? new Date(setYear, setMonth) : new Date();
    let year = setYear || now.getFullYear();
    //let year = 2003;
    let nextYear = 0;
    let month = setMonth || now.getMonth(); //没有+1方便后面计算当月总天数
    let nextMonth = (month + 1) > 11 ? 1 : (month + 1);
    let startWeek = new Date(year + ',' + (month + 1) + ',' + 1).getDay(); //目标月1号对应的星期
    let dayNums = new Date(year, nextMonth, 0).getDate(); //获取目标月有多少天
    let obj = {};
    let num = 0;
    if (month + 1 > 11) {
      nextYear = year + 1;
      dayNums = new Date(nextYear, nextMonth, 0).getDate();
    }
    arrLen = startWeek + dayNums;
    for (let i = 0; i < arrLen; i++) {
      if (i >= startWeek) {
        num = i - startWeek + 1;
        obj = {
          isToday: '' + year + (month + 1) + num,
          dateNum: num,
          weight: 5
        }
      } else {
        obj = {};
      }
      dateArr[i] = obj;
    }
    this.setData({
      dateArr: dateArr
    })
    let nowDate = new Date();
    let nowYear = nowDate.getFullYear();
    let nowMonth = nowDate.getMonth() + 1;
    let nowWeek = nowDate.getDay();
    let getYear = setYear || nowYear;
    let getMonth = setMonth >= 0 ? (setMonth + 1) : nowMonth;
    if (nowYear == getYear && nowMonth == getMonth) {
      this.setData({
        isTodayWeek: true,
        todayIndex: nowWeek
      })
    } else {
      this.setData({
        isTodayWeek: false,
        todayIndex: -1
      })
    }
  },
  /**
   * 上月切换
   */
  lastMonth: function () {
    //全部时间的月份都是按0~11基准，显示月份才+1
    let year = this.data.month - 2 < 0 ? this.data.year - 1 : this.data.year;
    //let year = 2003;
    let month = this.data.month - 2 < 0 ? 11 : this.data.month - 2;
    this.setData({
      year: year,
      month: (month + 1)
    })
    this.dateInit(year, month);
  },
  /**
   * 下月切换
   */
  nextMonth: function () {
    //全部时间的月份都是按0~11基准，显示月份才+1
    let year = this.data.month > 11 ? this.data.year + 1 : this.data.year;
    //let year = 2003;
    let month = this.data.month > 11 ? 0 : this.data.month;
    this.setData({
      year: year,
      month: (month + 1)
    })
    this.dateInit(year, month);

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.mapCtx = wx.createMapContext("myMap");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})